/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb.at;

/** 
 * 
 * 
 * @author jdp
 */
public final class SourceFile 
    extends syntelos.xb.Attribute
{
    public final static java.lang.String ATNAME = "SourceFile";
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb/at","xat:source-file");
    
    public SourceFile(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public SourceFile(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public SourceFile(){
        this(DOC_NIL);
    }

    public syntelos.iou.dom.Node decompile(){
        this.getConst();
        //
        return this;
    }
    public syntelos.iou.dom.Node compile(){

        this.getAttributeName().setNodeValue("utf8:SourceFile");

        this.getConst();
        //
        return this;
    }
    public syntelos.xb.CF.Constants.Utf8 getConst(){
        return (syntelos.xb.CF.Constants.Utf8)this.getChildData(syntelos.xb.IO.Data.CONST_UTF8,this);
    }
    public java.lang.String getConstString(){
        syntelos.xb.CF.Constants.Utf8 name = this.getConst();
        if (null != name)
            return name.getString();
        else
            throw new syntelos.xb.Error.State("Missing operand.");
    }
    public int getIndex(){
        syntelos.xb.CF.Constants.Utf8 name = this.getConst();
        if (null != name)
            return name.getIndex();
        else
            throw new syntelos.xb.Error.State("Missing operand.");
    }
    public void setIndex(int index){
        syntelos.xb.CF.Constants constants = this.getConstants();
        syntelos.xb.CF.Constants.Utf8 name = constants.getConstUtf8(index);
        this.setChildData(name,this);
    }
    public void setString(String value){
        syntelos.xb.CF.Constants constants = this.getConstants();
        syntelos.xb.CF.Constants.Utf8 name = constants.constUtf8(value);
        this.setChildData(name,this);
    }
    public int atlen(){
        return 2;
    }
    public void readCF(syntelos.xb.IO.Uri src, syntelos.xb.CF.Reader reader)
        throws java.io.IOException
    {
        if (2 != reader.readInt())
            throw new syntelos.xb.Error.Format();
        else {
            int name_index = reader.readUnsignedShort();
            this.setIndex(name_index);
        }
    }
    public void writeCF(syntelos.xb.IO.Uri dst, syntelos.xb.CF.Writer writer)
        throws java.io.IOException
    {
        this.getAttributeName().writeCF(dst,writer);
        writer.writeInt(2);
        int name_index = this.getIndex();
        writer.writeShort(name_index);
    }

}
